<?php
class DataProvider {
    
    private $connect;
    
    public function __construct($config) {
        if(is_string($config)) {
            if(file_exists($config)) {
                $mysql = parse_ini_file($config, true);
                $mysql = $mysql['mysql'];
            }else{
                echo "File config.ini is wrong or not exist!"; 
                exit(0);
            }
            
        }else{
            if(is_array($config)) {
                $mysql = $config;
            }else{
                echo "parameter is wrong type!";
                exit(0);
            }
        }
        
        foreach($mysql as $key=>$value) {
            $this->{$key} = $value;
        }
        $this->connect = mysql_connect($this->host, $this->user, $this->pass) or
                         die("Coult not connect to {$this->host}.");
        mysql_selectdb($this->dbname, $this->connect) or
                         die($this->Error());
        mysql_query("SET NAMES 'utf8'");    
    }
    
    public function ExecuteQuery($query) {
        $result = mysql_query($query, $this->connect);
        return $result;
    }
    
    public function Close() {
        $temp = mysql_close($this->connect) or die($this->Error());
    }
    
    public function Error() {
        return mysql_error($this->connect);
    }
    
    public function InsertId() {
        return mysql_insert_id($this->connect);
    }
    
    public function __destruct(){
        
    } 
}
?>